package com.bnlr.lrparking.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.appui.bank.model.BankCardM;
import com.yolanda.nohttp.rest.Request;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by rr on 2016/7/2.
 * 选择银行卡列表
 */
public class MeBankCardAdapter extends BaseAdapter {

    public Request<String> mRequest;
    private Context mcontext;
    private List<BankCardM.DataBean> list=new ArrayList<>();
    private LayoutInflater inflater;


    public MeBankCardAdapter(Context context, List<BankCardM.DataBean> list) {
        super();
        this.mcontext = context;
        this.list = list;
        inflater = LayoutInflater.from(mcontext);
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        final ViewHoder hoder;
        if (convertView == null) {
            hoder = new ViewHoder();
            convertView = inflater.inflate(R.layout.item_mebankcard, null);
            hoder.tv_mebank_num = (TextView) convertView.findViewById(R.id.tv_mebank_num);
            hoder.item_name=(TextView)convertView.findViewById(R.id.item_name);
            hoder.userbank_name=(TextView)convertView.findViewById(R.id.userbank_name);
            hoder.item_card=(TextView)convertView.findViewById(R.id.item_card);
            hoder.ivBank = (ImageView) convertView.findViewById(R.id.img_item_card);

            convertView.setTag(hoder);
        } else {
            hoder = (ViewHoder) convertView.getTag();
        }
        final BankCardM.DataBean bean = list.get(i);
        String str=bean.getAccountNo();
        hoder.tv_mebank_num.setText(str.substring(str.length()-4,str.length()));
        hoder.item_name.setText(bean.getBankName());
        hoder.userbank_name.setText(bean.getRealName());
        Glide.with(mcontext).load(bean.getBankIconUrl()).into(hoder.ivBank);
        if (bean.getCardType() == 0) {
            hoder.item_card.setText("借记卡");
        } else {
            hoder.item_card.setText("信用卡");
        }
        return convertView;
    }

    class ViewHoder {
        TextView tv_mebank_num,item_name,userbank_name,item_card;
        ImageView ivBank;
    }
}
